#include <stdio.h>
#include <stdint.h>

uint16_t crc16(uint8_t *data, uint16_t length) {
    uint16_t crc = 0xFFFF;
    uint16_t i, j;

    for (i = 0; i < length; i++) {
        crc ^= (uint16_t)data[i];
        for (j = 0; j < 8; j++) {
            if (crc & 0x0001) {
                crc = (crc >> 1) ^ 0x8005;
            } else {
                crc = crc >> 1;
            }
        }
    }
    return crc;
}

int main() {
    uint8_t testData[] = {0x01, 0x02, 0x03, 0x04, 0x05};
    uint16_t crcResult = crc16(testData, sizeof(testData));
    printf("CRC-16 result: 0x%04X\n", crcResult);
    return 0;
}